Non-volatile flash memory has limited lifetime. The lifetime of the flash memory may correspond to a number of program-erase (P/E) cycles that the flash memory can endure. To protect user data stored in the flash memory from corruption, parity data may be generated and stored along with user data to facilitate error detection and/or correction. If a higher code rate is used to encode data, less parity data is generated and stored. Because less parity data is stored when the higher code rate is used, the higher code rate may allow more storage capacity of the flash memory. On the other hand, if a lower code rate is used, more parity data is generated to protect user data from errors and thus less storage capacity of the flash memory becomes available.